package com.lansi.card.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.lansi.card.bean.Card;
import com.lansi.card.mapper.CardMapper;
import com.lansi.card.service.ex.CardAlreadyExistException;

@Service
public class CardService implements ICardService {

	@Resource
	private CardMapper cardMapper;
	
	/**
	 * 添加蓝牙工卡信息
	 * @param card
	 */
	public void getInsertCard(Card card) {
		String cardid = card.getCardid();
		Card card1 = cardMapper.selectCardByCardid(cardid);
		if(card1 == null) {
			cardMapper.insertCard(card);
		}else {
			throw new CardAlreadyExistException("该工卡号已存在！");
		}
		
	}
	
	/**
	 * 根据工卡号删除蓝牙工卡信息
	 * @param cardid
	 */
	public void delCardByCardid(String cardid) {
		cardMapper.deleteCardByCardid(cardid);
	}
	
	/**
	 * 根据工卡号修改蓝牙工卡信息
	 * @param card
	 */
	public void getUpdateCardByCardid(Card card) {
		cardMapper.updateCardByCardid(card);
	}
	
	/**
	 * 根据工卡号查询蓝牙工卡信息
	 * @param cardid
	 * @return
	 */
	public Card getCardByCardid(String cardid) {
		return cardMapper.selectCardByCardid(cardid);
		
	}
	
	/**
	 * 根据公司编号sn进行蓝牙工卡信息分页查询
	 * @param sn
	 * @param offset
	 * @param count
	 * @return
	 */
	public List<Card> getCardBySn(String sn,Integer offset,Integer count){
		return cardMapper.selectCardBySn(sn, offset, count);
	}
	
	/**
	 * 对蓝牙工卡信息的分页查询
	 * @param offset
	 * @param count
	 * @return
	 */
	public List<Card> getCardAll(Integer offset,Integer count){
		return cardMapper.selectCardAll(offset, count);
	}
	
	/**
	 * 所有蓝牙工卡信息的条数
	 * @return
	 */
	public Integer getSizeCardAll() {
		return cardMapper.selectSizeCardAll();
	}
	
	/**
	 * 根据公司编号sn查询蓝牙工卡信息的条数
	 * @param sn
	 * @return
	 */
	public Integer getSizeCardBySn(String sn) {
		return cardMapper.selectSizeCardBySn(sn);
	}

}
